package com.hgb.mall.admin.services.impl;

import com.github.pagehelper.PageHelper;
import com.hgb.mall.admin.services.CmsSubjectService;
import com.hgb.mall.mbg.entity.CmsSubject;
import com.hgb.mall.mbg.mapper.CmsSubjectDynamicSqlSupport;
import com.hgb.mall.mbg.mapper.CmsSubjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static org.mybatis.dynamic.sql.SqlBuilder.isLikeWhenPresent;

/**
 * 商品专题Service实现类
 * Created by hgb on 2020/6/1.
 */
@Service
public class CmsSubjectServiceImpl implements CmsSubjectService {
    @Autowired
    private CmsSubjectMapper subjectMapper;

    @Override
    public List<CmsSubject> listAll() {
        return subjectMapper.select(c -> c);
    }

    @Override
    public List<CmsSubject> list(String keyword, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return subjectMapper.select(c -> c
                .where(CmsSubjectDynamicSqlSupport.title, isLikeWhenPresent(keyword).then(s -> "%" + s + "%")));

    }
}
